(function(win){

    var docs = ['/doc/1.html','/doc/2.html'] ;

    docs.get = function(index){
        var promise = null ;
        if( index < 0 || index > this.length - 1 ){
            var deferred = $.deferred() ;
            deferred.solve('<h1>参数有误</h1>') ;
            promise = deferred.promise() ;
        } else {
            promise= $.ajax(this[index],{
                dataType : 'html'
            }) ;
        }
        promise.done(function(html){
            var contain = $('#markdown') ;
            contain.empty().append(html) ;
        }) ;
        promise.fail(function(error){
            console.log(error) ;
        }) ;
        return promise;
    } ;

    var curPage = (function(maxLen){
        var cur = 0 ;
        return {
            next : function( ){
                if( cur < maxLen - 1 ){
                    return ++cur ;
                } else {
                    return cur=0 ;
                }
            } ,
            pri : function(){
                if( cur > 0  ){
                    return --cur;
                }else{
                    return cur=maxLen-1;
                }
            } ,
            getCur: function(){
                return cur ;
            }
        } ;
    }(docs.length)) ;
    var svg = docs.get(curPage.getCur()) ;

    //@note 按方向键切换
    $(window).on('keyup',function(e){
        if(e.which===39){
            docs.get(curPage.next()) ;
        }
        if(e.which===37){
            docs.get(curPage.pri()) ;
        }
    }) ;

}(window)) ;